define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'statistics.online_record/index',
        add_url: 'statistics.online_record/add',
        edit_url: 'statistics.online_record/edit',
        delete_url: 'statistics.online_record/delete',
        export_url: 'statistics.online_record/export',
        modify_url: 'statistics.online_record/modify',
        group_auth: 'auth'
    };

    var Controller = {

        index: function () {


            $.ajax({
                type: "GET",
                url: init.group_auth,
                success: function (relus) {

                    ea.table.render({
                        init: init,
                        toolbar:['refresh'],
                        defaultToolbar:['filter', {
                            title: '搜索',
                            layEvent: 'TABLE_SEARCH',
                            icon: 'layui-icon-search',
                            extend: 'data-table-id="' + 'online_record' + '"'
                        }],
                        cols: [[
                            // {type: 'checkbox'},
                            // {field: 'id', title: 'id'},
                            {field: 'rid',width:80, title: '房间号'},
                            {field: 'username', title: '用户账号'},
                            {field: 'extension', title: '归属人'},
                            {field: 'group',width:80, title: '类型',search: 'select', selectList: relus},
                            {field: 'ip', title: '地区/IP',templet:function (e) {
                                let html = `<span>IP:` + e.ip + `</span><br/><span>`;

                                if (e.create_home != '') {
                                    html += `地区：` + e.home + `</span>`
                                }
                                return html;
                            },search:false},
                            {field: 'start_time',width:141, title: '进入时间', search: 'range'},
                            {field: 'end_time',width:141, title: '退出时间', search: 'range'},
                            {field: 'duration',width:85, title: '在线时长',search: 'select',selectList: {120:"两分钟内",300:"5分钟以上",1800:"30分钟以上"}},
                            // {width: 250, title: '操作', templet: ea.table.tool},

                        ]],
                    });

                }
            })


           
            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };
    return Controller;
});